package org.coding.springbootdemocommandline.beanlife;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * @author guoxuehe
 * @date 2021/1/26 10:26
 * @desc
 **/
public class Person implements BeanFactoryAware, BeanNameAware, InitializingBean, DisposableBean {

    private String name;
    private String address;
    private String phone;

    private BeanFactory beanFactory;
    private String beanName;

    public Person() {
        System.out.println("[构造器]调用person的构造器实例化");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("[BeanFactoryAware]调用BeanFactoryAware.setBeanFactory");
        this.beanFactory = beanFactory;
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("[BeanNameAware]调用BeanNameAware.setBeanName");
        this.beanName = beanName;
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("[DisposableBean]调用DisposableBean.destroy");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("[InitializingBean]调用InitializingBean.afterPropertiesSet");
    }

    public void initMethod() {
        System.out.println("init-method 调用bean的init-method方法");
    }
    public void mydestroy(){
        System.out.println("destroy-method 调用bean的destroy-method方法");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        System.out.println("[属性注入]注入name属性");
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        System.out.println("[属性注入]注入address属性");
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        System.out.println("[属性注入]注入phone属性");
        this.phone = phone;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", phone=" + phone +
                ", beanFactory=" + beanFactory +
                ", beanName='" + beanName + '\'' +
                '}';
    }


}
